import {createRouter, createWebHistory} from 'vue-router'
import Layout from '/src/views/layout/index'
import common from "/src/router/common";
import admin from "/src/router/admin";
import student from "/src/router/student";
import teacher from "/src/router/teacher";

const children = [
    ...admin,
    ...student,
    ...teacher
]
const routes = [
    {
        path: '/',
        name: 'Home',
        component: Layout,
        children:children
    },
    ...common
]
const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

router.beforeEach((to, from, next) => {
    document.title = to.meta.title ? to.meta.title : '人脸识别校园管理系统'
    next()
})
// router.beforeEach(({name}, from, next) => {
//     // 获取 JWT Token
//     if (localStorage.getItem('Authorization')) {
//         // 如果用户在login页面
//         if (name === 'login') {
//             next('/');
//         } else {
//             next();
//         }
//     } else {
//         if (name === 'login') {
//             next();
//         } else {
//             next({name: 'login'});
//         }
//     }
// })
export default router
